import type { SysDict } from '@nbase/db';
import type { IDict, IPaginationResponse } from '@nbase/shared';

/**
 * SysDict -> IDict 映射（对外返回使用）
 */
export function toDict(dict: SysDict): IDict {
  return {
    id: dict.id,
    code: dict.code,
    name: dict.name,
    status: dict.status,
    description: dict.description,
    createdAt: dict.createdAt?.toISOString(),
    updatedAt: dict.updatedAt?.toISOString(),
  };
}

/**
 * 分页结果 SysDict -> IDict
 */
export function toDictPage(page: IPaginationResponse<SysDict>): IPaginationResponse<IDict> {
  return {
    ...page,
    items: page.items.map(toDict),
  };
}

